package com.mingtech.sscarddirver;

import android.util.Log;

public class Reader {
	private static String	TAG	= "MTReader";
	static {
		try {
			System.loadLibrary("modcomm");
			System.loadLibrary("stdcomm");
			System.loadLibrary("SSCardDriverMT");
			Log.d(TAG, "loadLibrary SSCardDriverMT succeed!");	
		} catch (Throwable ex) {
			String mLoadErrMsg = ex.toString();
			Log.e(TAG, mLoadErrMsg);
		}
	}
	
	public static native long iOpenUsbDevice(int iVid,int iPid,int iUsbFD,byte[] pUsbPath);
	public static native long iOpenSerialDevice(int devid,int proid,int iBuad,byte[] pSerialPath);
	public static native long iCloseDevice();

	public static native long iReadCardBas(int iType,byte[] pOutInfo);
	public static native long iReadCardBas_HSM_Step1(int iType,byte[] pOutInfo);
	public static native long iReadCardBas_HSM_Step1tostep2(byte[] indata, byte[] outdata);
	public static native long iReadCardBas_HSM_Step2(byte[] pKey,byte[] pOutInfo);

	public static native long iReadCard(int iType, int iAuthType,byte[] pCardInfo,byte[] pFileAddr,byte[] pOutInfo);
	//通用读卡,带参数PIN
	public static native long iReadCardWithPIN(int iType, int iAuthType,byte[] pCardInfo,byte[] pFileAddr,byte[] pPINData,byte[] pOutInfo);
	public static native long iReadCard_HSM_Step1(int iType,byte[] pCardInfo,byte[] pFileAddr,byte[] pOutInfo);
	public static native long iReadCard_HSM_Step1tostep2(byte[] indata, byte[] outdata);
	public static native long iReadCard_HSM_Step2(byte[] pKey,byte[] pOutInfo);

	public static native long iWriteCard(int iType,byte[] pCardInfo,byte[] pFileAddr,byte[] pWriteData,byte[] pOutInfo);
	public static native long iWriteCard_HSM_Step1(int iType,byte[] pCardInfo,byte[] pFileAddr,byte[] pOutInfo);
	public static native long iWriteCard_HSM_Step1tostep2(byte[] indata, byte[] outdata);
	public static native long iWriteCard_HSM_Step2(byte[] pKey,byte[] pWriteData,byte[] pOutInfo);

	public static native long iVerifyPIN(int iType,byte[] pOutInfo);
	//校验用户PIN，传入PIN
	public static native long iVerifyPINWithPIN(int iType,byte[] pPINData,byte[] pOutInfo);
	public static native long iChangePIN(int iType,byte[] pOutInfo);
	//修改用户PIN，传入PIN
	public static native long iChangePINWithPIN(int iType,byte[] pOldPINData,byte[] pNewPINData,byte[] pOutInfo);

	public static native long iReloadPIN(int iType,byte[] pCardInfo,byte[] pOutInfo);
	//重置用户PIN，传入PIN
	public static native long iReloadPINWithPIN(int iType,byte[] pCardInfo,byte[] pNewPIN,byte[] pOutInfo);
	public static native long iReloadPIN_HSM_Step1(int iType,byte[] pCardInfo,byte[] pOutInfo);
	public static native long iReloadPIN_HSM_Step1tostep2(byte[] indata, byte[] outdata);
	public static native long iReloadPIN_HSM_Step2(byte[] pKey,byte[] pOutInfo);
	public static native long iReloadPIN_HSM_Step2tostep3(byte[] indata, byte[] outdata);
	public static native long iReloadPIN_HSM_Step3(byte[] pKey,byte[] pOutInfo);

	public static native long iUnblockPIN(int iType,byte[] pCardInfo,byte[] pOutInfo);
	public static native long iUnblockPIN_HSM_Step1(int iType,byte[] pCardInfo,byte[] pOutInfo);
	public static native long iUnblockPIN_HSM_Step1tostep2(byte[] indata, byte[] outdata);
	public static native long iUnblockPIN_HSM_Step2(byte[] pKey,byte[] pOutInfo);
	public static native long iUnblockPIN_HSM_Step2tostep3(byte[] indata, byte[] outdata);
	public static native long iUnblockPIN_HSM_Step3(byte[] pKey,byte[] pOutInfo);

	public static native long iDoDebit(int iType,byte[] pCardInfo,byte[] pPayInfo,byte[] pOutInfo);
	//消费交易，传入PIN
	public static native long iDoDebitWithPIN(int iType,byte[] pCardInfo,byte[] pPayInfo,byte[] pPINData,byte[] pOutInfo);
	
	public static native long iDoDebit_HSM_Step1(int iType,byte[] pCardInfo,byte[] pPayInfo,byte[] pOutInfo);
	public static native long iDoDebit_HSM_Step1toStep2(byte[] indata, byte[] outdata);
	public static native long iDoDebit_HSM_Step2(byte[] pKey,byte[] pOutInfo);

	/** 读交易记录 */
	public static native long iReadDebitRecord(int iType,byte[] pOutInfo);
	
	//读交易记录,传入PIN
	public static native long iReadDebitRecordWithPIN(int iType,byte[] pPINData,byte[] pOutInfo);
	
	/** 读取金融ic卡号 */
	// 二代证
	public static native long IDCardReadAll(int[] idcMsgLen, byte[] idcMsg, int isReadFinger);
	public static native long IDCardGetModeID(byte IDLen[], byte sIDData[]);
	public static native long IDCardReadIDNUM(byte rlen[], byte receivedata[]);
	
	// 工具函数
	public static native long HexToAsc(byte hex[], byte asc[], int len);
	public static native long AscToHex(byte asc[], byte hex[], int len);

	/**
	 * [EnabledLog 开启日志函数]
	 * @param  sLogSavaPath [日志保存的路径,如: "/mnt/sdcard/SSCardDriver/" ]
	 * @param  sLogDirName  [日志保存的文件夹名字,如: "Readder"]
	 * @return              [0:成功,其他失败]
	 */
	public static native int EnabledLog(byte[] sLogSavaPath,byte[] sLogDirName);
	public static native int DisEnabledLog();
}

